﻿Module VisioPrez
    'Module principal de la solution Add-In de présentation pour Visio 
    Public Const visCmdAppMaximize As Short = 1864
    Public Const visCmdLayoutDynamic As Short = 1493
    Public Const visCmdFullScreenMode As Short = 1492
    Public Const visWinIDPanZoom As Short = 1653
    Public Const visLayerVisible As Short = 4
    Public Const visWSMaximized As Integer = &H40000000

    Public oApp As Microsoft.Office.Interop.Visio.Application = Nothing
    Public oFormPrez As New FormPrez  
    Public CheminVSD As String = ""
    Public ListePrez As New ColPrez

    Public Sub SaveInVSD(ByRef oPrez As ClassPrez, ByRef Doc As Microsoft.Office.Interop.Visio.Document)
        Doc.SolutionXMLElement("VisioPrez") = oPrez.XML
        'Pour debug
        'Windows.Forms.Clipboard.SetText(oPrez.XML)
    End Sub

    Public Sub LoadFromVSD(ByRef oPrez As ClassPrez, ByRef Doc As Microsoft.Office.Interop.Visio.Document)
        If Doc.SolutionXMLElementExists("VisioPrez") Then oPrez.XML = Doc.SolutionXMLElement("VisioPrez")
         'Pour Debug
        Windows.Forms.Clipboard.SetText(oPrez.XML)
    End Sub

    Public Function CaptureEcranFull() As System.Drawing.Bitmap
        Return CaptureEcran(0, 0, Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width, Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height)
    End Function

    Public Function CaptureEcran(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer) As Drawing.Bitmap
        Dim Img As New System.Drawing.Bitmap(Width, Height)
        Dim g As Drawing.Graphics = Drawing.Graphics.FromImage(Img)
        g.CopyFromScreen(X, Y, 0, 0, Img.Size)
        g.Dispose()
        Return Img
    End Function

    Private Function GetActivePrez() As ClassPrez
        Dim oPrez As ClassPrez = Nothing
        If Not oApp Is Nothing Then
            If Not oApp.ActiveDocument Is Nothing Then
                If ListePrez.Contains(oApp.ActiveDocument.ID) Then
                    oPrez = ListePrez(oApp.ActiveDocument.ID)
                Else
                    'On se rattrape, mais on devrait pas venir ici...
                    oPrez = New ClassPrez
                    oPrez.DocID = oApp.ActiveDocument.ID
                    ListePrez.add(oPrez)
                End If
            End If
        End If
        Return oPrez
    End Function

    Public Sub NouvelleDiapo()
        Dim oPrez As ClassPrez = GetActivePrez()
        If Not oPrez Is Nothing Then oPrez.NouvelleDiapo()
        oPrez = Nothing
    End Sub

    Public Sub EditPrez()
        Dim oPrez As ClassPrez = GetActivePrez()
        If Not oPrez Is Nothing Then oPrez.Edit()
        oPrez = Nothing
    End Sub

    Public Sub ReprendreDiapo()
        Dim oPrez As ClassPrez = GetActivePrez()
        If Not oPrez Is Nothing Then oPrez.ReprendreDiapo()
        oPrez = Nothing
    End Sub

    Public Sub SupprimerDiapo()
        Dim oPrez As ClassPrez = GetActivePrez()
        If Not oPrez Is Nothing Then oPrez.SupprimerDiapo()
        oPrez = Nothing
    End Sub

    Public Sub AllerDiapoSuivante()
        Dim oPrez As ClassPrez = GetActivePrez()
        If Not oPrez Is Nothing Then oPrez.AllerSuivante()
        oPrez = Nothing
    End Sub

    Public Sub AllerDiapoPrecedente()
        Dim oPrez As ClassPrez = GetActivePrez()
        If Not oPrez Is Nothing Then oPrez.AllerPrecedente()
        oPrez = Nothing
    End Sub

    Public Sub AllerDebut()
        Dim oPrez As ClassPrez = GetActivePrez()
        If Not oPrez Is Nothing Then oPrez.AllerDebut()
        oPrez = Nothing
    End Sub

    Public Sub AllerFin()
        Dim oPrez As ClassPrez = GetActivePrez()
        If Not oPrez Is Nothing Then oPrez.AllerFin()
        oPrez = Nothing
    End Sub

    Public Sub ExporterPowerPoint(ByVal Modele As String, ByVal DataType As Microsoft.Office.Interop.PowerPoint.PpPasteDataType)
        Dim oPrez As ClassPrez = GetActivePrez()
        If Not oPrez Is Nothing Then oPrez.ExporterPP(Modele, DataType)
        oPrez = Nothing
    End Sub

    Public Sub ExporterPowerPoint_Captures(ByVal Modele As String)
        Dim oPrez As ClassPrez = GetActivePrez()
        If Not oPrez Is Nothing Then oPrez.ExporterPP_Capture(Modele)
        oPrez = Nothing
    End Sub

    Public Function GetPPTemplates() As Collection
        Dim oCol As New Collection
        Dim oPP As New Microsoft.Office.Interop.PowerPoint.Application
        oPP.P()
        oPP.Quit()
        oPP = Nothing
        Return oCol
    End Function

End Module
